package ${package.Controller};

<#--import com.debao.cloud.modules.carbon.dto.${entity}DTO;-->
<#--import com.debao.cloud.modules.carbon.query.${entity}PageQuery;-->
<#--import com.debao.cloud.modules.carbon.query.${entity}ListQuery;-->
<#--import com.debao.cloud.modules.carbon.query.${entity}InfoQuery;-->
<#--import com.debao.cloud.modules.carbon.query.${entity}InsertQuery;-->
<#--import com.debao.cloud.modules.carbon.query.${entity}UpdateQuery;-->
<#--import com.debao.cloud.modules.carbon.vo.${entity}PageVO;-->
<#--import com.debao.cloud.modules.carbon.vo.${entity}ListVO;-->
<#--import com.debao.cloud.modules.carbon.vo.${entity}InfoVO;-->
<#--import com.debao.cloud.common.core.base.AppResult;-->
<#--import com.debao.cloud.modules.carbon.service.${entity}Service;-->
<#assign myDateType = ["LocalDateTime","LocalDate"]/>
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.extern.slf4j.Slf4j;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.hutool.core.bean.BeanUtil;

import javax.annotation.Resource;
import java.util.List;


/**
 * ${table.comment!}控制层
 *
 * @author ${author}
 * @date ${date}
 */
@Schema(title = " ${table.controllerName}", name = "${table.comment}文档")
@Slf4j
@RestController
@RequestMapping("/api/sys/device")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
    <#else>
public class ${table.controllerName} {
    </#if>

    @Resource
    private ${table.serviceName} ${table.serviceName?uncap_first};


    @Schema(title = "${table.comment}分页", name = "备注信息")
    @PostMapping("/${table.entityName?uncap_first}/listPage")
    public AppResult<Page<${table.entityName}PageVO>> listPage(@Validated @RequestBody(required = false) ${table.entityName}PageQuery query) {
        // 组装分页参数与查询条件
        Page<${table.entityName}PO> pageQuery = new Page<>(query.getCurrent(), query.getSize());
        ${table.entityName}DTO dto = BeanUtil.copyProperties(query, ${table.entityName}DTO.class);
        // 获取分页数据
        Page<${table.entityName}PageVO> pageVO = ${table.serviceName?uncap_first}.listPage(pageQuery, dto);
        return AppResult.success(pageVO);
    }

    @Schema(title = "${table.comment}列表", name = "备注信息")
    @PostMapping("/${table.entityName?uncap_first}/list")
    public AppResult<List<${table.entityName}ListVO>> list(@Validated @RequestBody(required = false) ${table.entityName}ListQuery query) {
        // 组装查询条件
        ${table.entityName}DTO dto = BeanUtil.copyProperties(query, ${table.entityName}DTO.class);
        // 获取列表数据
        List<${table.entityName}DTO> listDTO = ${table.serviceName?uncap_first}.list(dto);
        List<${table.entityName}ListVO> listVO = BeanUtil.copyToList(listDTO, ${table.entityName}ListVO.class);
        return AppResult.success(listVO);
    }

    @Schema(title = "${table.comment}新增", name = "备注信息")
    @PostMapping("/${table.entityName?uncap_first}/insert")
    public AppResult<Void> insert(@Validated @RequestBody(required = false) ${table.entityName}InsertQuery insertQuery) {
        ${table.entityName}DTO dto = BeanUtil.copyProperties(insertQuery, ${table.entityName}DTO.class);
        ${table.serviceName?uncap_first}.insert(dto);
        return AppResult.success();
    }

    @Schema(title = "${table.comment}修改", name = "备注信息")
    @PostMapping("/${table.entityName?uncap_first}/updateById")
    public AppResult<Void> updateById(@Validated @RequestBody(required = false) ${table.entityName}UpdateQuery updateQuery) {
        ${table.entityName}DTO dto = BeanUtil.copyProperties(updateQuery, ${table.entityName}DTO.class);
        ${table.serviceName?uncap_first}.updateById(dto);
        return AppResult.success();
    }

    @Schema(title = "${table.comment}详情", name = "备注信息")
    @PostMapping("/${table.entityName?uncap_first}/getById")
    public AppResult<${table.entityName}InfoVO> getById(@Validated @RequestBody(required = false) ${table.entityName}InfoQuery query) {
        ${table.entityName}DTO detailDTO = ${table.serviceName?uncap_first}.getById(query.getId());
        return AppResult.success(BeanUtil.copyProperties(detailDTO, ${table.entityName}InfoVO.class));
    }





}
</#if>